import 'package:flutter/material.dart';

class ScrollNotificationDemo extends StatefulWidget {

  const ScrollNotificationDemo({super.key});

  @override
  State createState() => ScrollNotificationDemoState();

}

class ScrollNotificationDemoState extends State<ScrollNotificationDemo> {

  String _progress = "0%";

  @override
  Widget build(BuildContext context) {
     return Scaffold(
       appBar: AppBar(
         title: const Text('Notification'),
         backgroundColor: Colors.deepPurple,
       ),
       body: Scrollbar(
           thickness: 0,
           child: NotificationListener<ScrollNotification>(
             onNotification: (ScrollNotification notification) {
               double progress = notification.metrics.pixels / notification.metrics.maxScrollExtent;
               setState(() {
                 _progress = '${(progress * 100).toInt()}%';
               });
               //false进度条才有效果
               return false;
             },
             child: Stack(
               alignment: Alignment.center,
               children: <Widget>[
                 ListView.builder(
                     itemCount: 100,
                     itemBuilder: (context,index) {
                       EdgeInsetsGeometry insets;
                       if(100 - 1 == index ) {
                         insets = const EdgeInsets.only(top: 10,left: 5,right: 5,bottom: 10);
                       } else {
                         insets = const EdgeInsets.only(top: 10,left: 5,right: 5);
                       }
                       return Container(
                         margin: insets,
                         height: 45,
                         child:
                         Material(
                           child: Ink(
                             decoration: BoxDecoration(
                               color:Colors.yellow,
                               borderRadius: BorderRadius.circular(10),
                             ),
                             child: InkWell(
                               borderRadius: BorderRadius.circular(10),
                               onTap: () {
                                 print("onTap---object");
                               },
                               child: Center(child: Text('$index',style: const TextStyle(color: Colors.blue,fontSize: 15),textAlign: TextAlign.center,),
                               ),
                             ),
                           ),
                         ),
                       );
                     }
                 ),
                 CircleAvatar(
                   radius: 30,
                   backgroundColor: Colors.cyan,
                   child: Text(_progress),
                 )
               ],
             ),
           ),
       ),
     );
  }

}